﻿/* 
 * Enterprise Library Extensions - DI + ORM.
 * Copyright (C) 2006
 *
 * GNU General Public License
 *
 * This program is free software; you can redistribute 
 * it and/or modify it under the terms of the GNU General Public License 
 * as published by the Free Software Foundation; either version 2 of the 
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 * See the GNU General Public License for more details.
 */
#region Using directives

using System;
using System.Collections;
using System.Text;

#endregion

namespace ELE.EnterpriseLibrary.Naming.Configuration
{
  /// <summary>
  /// Specialized type safe collection of ComponentInitializer objects
  /// </summary>
  public class ComponentInitializerCollection : CollectionBase
  {
    /// <summary>
    /// Indexer to access objects of the collection
    /// </summary>
    public ComponentInitializer this[int index]
    {
      get { return ((ComponentInitializer)(List[index])); }
      set { List[index] = value; }
    }
    /// <summary>
    /// Add a name to the collection
    /// </summary>
    /// <param name="val">name object to add</param>
    /// <returns>new count</returns>
    public int Add(ComponentInitializer val)
    {
      return List.Add(val);
    }
    /// <summary>
    /// Insert a name in the collection at a specific position
    /// </summary>
    /// <param name="index">position to insert the name at</param>
    /// <param name="val">name to insert</param>
    public void Insert(int index, ComponentInitializer val)
    {
      List.Insert(index, val);
    }
    /// <summary>
    /// Remove a name from the collection
    /// </summary>
    /// <param name="val">the name to remove</param>
    public void Remove(ComponentInitializer val)
    {
      List.Remove(val);
    }
    /// <summary>
    /// Check for a name in the collection
    /// </summary>
    /// <param name="val"></param>
    /// <returns>true if the collection contains an object that matches the given name</returns>
    public bool Contains(ComponentInitializer val)
    {
      return List.Contains(val);
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="index"></param>
    /// <param name="value"></param>    
    protected override void  OnInsert(int index, object value)
    {
      base.OnInsert(index,value);
      if (!(value is ComponentInitializer))
        throw new ArgumentException("value must be of type ELE.EnterpriseLibrary.Naming.Configuration.ComponentInitializer.", "value");
    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="index"></param>
    /// <param name="oldValue"></param>
    /// <param name="newValue"></param>
    protected override void OnSet(int index, object oldValue, object newValue)
    {
      base.OnSet(index,oldValue,newValue);
      if (!(newValue is ComponentInitializer))
        throw new ArgumentException("newValue must be of type ELE.EnterpriseLibrary.Naming.Configuration.ComponentInitializer.", "newValue");
    }
    /// <summary>
    /// Validation method
    /// </summary>
    /// <param name="value"></param>
    protected override void OnValidate(Object value)
    {
      base.OnValidate(value);
      if (!(value is ComponentInitializer))
        throw new ArgumentException("value must be of type ELE.EnterpriseLibrary.Naming.Configuration.ComponentInitializer.", "value");
    }
  }
}
